package com.fr.data.core.define;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.util.ListSet;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.ChartData;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataXMLUtils;
import java.util.List;

public abstract class TableDataDefinition extends TopDefinition
  implements FilterDefinition
{
  private static final long serialVersionUID = 6650119421972084763L;
  protected TableData tableData;
  protected String categoryName;

  public TableDataDefinition()
  {
  }

  public TableDataDefinition(TableData paramTableData, String paramString)
  {
    this.tableData = paramTableData;
    this.categoryName = paramString;
  }

  public void setTableData(TableData paramTableData)
  {
    this.tableData = paramTableData;
  }

  public TableData getTableData()
  {
    return this.tableData;
  }

  public void setCategoryName(String paramString)
  {
    this.categoryName = paramString;
  }

  public String getCategoryName()
  {
    return this.categoryName;
  }

  public void reset()
  {
    this.tableData = null;
    this.categoryName = null;
  }

  protected int createCategoryNameArray(List paramList)
    throws TableDataException
  {
    int i = -1;
    int j = this.tableData.getColumnCount();
    for (int k = 0; k < j; ++k)
    {
      ListSet localListSet;
      int i1;
      if (ComparatorUtils.tableDataColumnNameEquals(this.tableData.getColumnName(k), this.categoryName))
      {
        localListSet = new ListSet();
        i = k;
        int l = this.tableData.getRowCount();
        for (i1 = 0; i1 < l; ++i1)
        {
          Object localObject = this.tableData.getValueAt(i1, k);
          localListSet.add(localObject);
        }
        for (i1 = 0; i1 < localListSet.size(); ++i1)
          paramList.add(localListSet.get(i1));
      }
    }
    if ((this.categoryName != null) && (i == -1))
      paramList.add(this.categoryName);
    return i;
  }

  public abstract ChartData createChartData();

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (this.tableData != null)
      DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, this.tableData);
    if (this.categoryName != null)
      paramXMLPrintWriter.startTAG("CategoryName").attr("value", this.categoryName).end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      Object localObject;
      String str = paramXMLableReader.getTagName();
      if ("TableData".equals(str))
      {
        localObject = DataXMLUtils.readXMLTableData(paramXMLableReader);
        if (localObject != null)
          setTableData((TableData)localObject);
      }
      else if ("CategoryName".equals(str))
      {
        if ((localObject = paramXMLableReader.getAttr("value")) != null)
          setCategoryName((String)localObject);
      }
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return clone();
  }
}